import numpy as np
import sys # 导入 sys 模块，用于获取 Python 版本

def print_ones(rows, cols):
    """
    Creates and prints a NumPy array of ones with the given shape.
    Returns the total number of elements.
    """
    print(f"Using NumPy version: {np.__version__}")
    print(f"Running with Python version: {sys.version}")

    # 创建一个指定形状和数据类型的 NumPy 数组，所有元素为 1.0
    A = np.ones(shape=(rows, cols), dtype=float)

    # 打印数组
    print("NumPy array:\n", A)

    # 返回元素总数，用于验证 C++ 代码能否接收返回值
    num_elements = rows * cols
    return num_elements

if __name__ == "__main__":
    # 可以在命令行直接运行此脚本进行简单测试
    # 例如: python use_numpy.py
    # 或者传递参数: python use_numpy.py 2 3
    import sys
    if len(sys.argv) > 2:
        try:
            r = int(sys.argv[1])
            c = int(sys.argv[2])
            result = print_ones(r, c)
            print(f"Function returned: {result}")
        except ValueError:
            print("Usage: python use_numpy.py [rows cols]")
    else:
            result = print_ones(2, 3) # 默认执行 2x3 矩阵
            print(f"Function returned (default 2x3): {result}")